import React,{Fragment,Component} from 'react';
import Frame from './components/Frame';
import {Switch,Route,Redirect} from 'react-router-dom';
import {adminRouter} from './routers';
import {Video,Article} from './pages'
// axios.post('/api/upload/uploadAuthorImg');
const adminchildren =adminRouter.filter(res=>res.children)
const admin =adminRouter.filter(res=>{
  if (!res.children) {
    return res
  }
})
 class App extends Component {
  render() {
    return (
     <Fragment>
       <Frame>
          <Switch>
            {
              admin.map(res=>{
                return  <Route  
                path={res.pathname}
                key={res.pathname}
                render={Props=>{
                  return (
                    <res.component {...Props} ></res.component>
                  )
                }}></Route>
              })
            }
        
              {
                adminchildren.map(route=>{
                  return (
                    <Route
                    path={route.pathname}
                    key={route.pathname}
                    render={Props=>{
                      return (
                        <route.component {...Props} ></route.component>
                      )
                    }}
                      >
                        {
                         route.children.map(res=>{
                          return (
                            <Route
                              path={res.pathname}
                              exact
                              key={res.pathname}
                              render={Props=>{
                                  return (
                                    <res.component {...Props} ></res.component>
                                  )
                                }}
                            >
                            </Route>
                          )
                         }) 
                        }
                    </Route>
                         )
                })
              }
            <Redirect 
                from='/admin'
                exact
                to="/admin/home/video"></Redirect>
             <Redirect to='/404'  ></Redirect>
          </Switch>
       </Frame>
     </Fragment>
    );
  }
}
export default App;
